package com.member.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.member.common.enums.OrderDeleteEnum;
import com.member.shop.domain.SysBizAgreement;
import com.member.shop.domain.SysBizJingang;
import com.member.shop.mapper.SysBizAgreementMapper;
import com.member.shop.service.ISysBizAgreementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 协议Service业务层处理
 *
 * @author wangxin
 * @date 2024-01-03
 */
@Service
public class SysBizAgreementServiceImpl extends ServiceImpl<SysBizAgreementMapper, SysBizAgreement> implements ISysBizAgreementService {
    @Resource
    private SysBizAgreementMapper sysBizAgreementMapper;

    /**
     * 查询协议
     *
     * @param id 协议主键
     * @return 协议
     */
    @Override
    public SysBizAgreement selectSysBizAgreementById(Long id) {
        return sysBizAgreementMapper.selectById(id);
    }

    /**
     * 查询协议列表
     *
     * @param queryWrapper 协议
     * @return 协议
     */
    @Override
    public List<SysBizAgreement> selectSysBizAgreementList(LambdaQueryWrapper<SysBizAgreement> queryWrapper) {
        return sysBizAgreementMapper.selectList(queryWrapper);
    }

    /**
     * 新增协议
     *
     * @param sysBizAgreement 协议
     * @return 结果
     */
    @Override
    public int insertSysBizAgreement(SysBizAgreement sysBizAgreement) {
        return sysBizAgreementMapper.insert(sysBizAgreement);
    }

    /**
     * 修改协议
     *
     * @param sysBizAgreement 协议
     * @return 结果
     */
    @Override
    public int updateSysBizAgreement(SysBizAgreement sysBizAgreement) {
        return sysBizAgreementMapper.updateById(sysBizAgreement);
    }

    /**
     * 批量删除协议
     *
     * @param ids 需要删除的协议主键
     * @return 结果
     */
    @Override
    public int deleteSysBizAgreementByIds(Long[] ids) {
        return sysBizAgreementMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除协议信息
     *
     * @param id 协议主键
     * @return 结果
     */
    @Override
    public int deleteSysBizAgreementById(Long id) {
        return sysBizAgreementMapper.deleteById(id);
    }

    /**
     * 查询协议列表(查询关联的商品表)
     *
     * @param sysBizAgreement 协议
     * @return 协议集合
     */
    @Override
    public List<SysBizAgreement> selectSysBizAgreementList(SysBizAgreement sysBizAgreement) {
        return sysBizAgreementMapper.selectSysBizAgreementList(sysBizAgreement);
    }

    //判断该商品是否被设置会员招商商品
    @Override
    public boolean hasExist(Long id) {
        LambdaQueryWrapper<SysBizAgreement> sysBizAgreementLambdaQueryWrapper = new LambdaQueryWrapper<>();
        sysBizAgreementLambdaQueryWrapper.eq(SysBizAgreement::getCourtshipShopId,id);
        List<SysBizAgreement> SysBizAgreements = sysBizAgreementMapper.selectList(sysBizAgreementLambdaQueryWrapper);
        if(SysBizAgreements.isEmpty()){
            return false;
        }
        return true;
    }
}
